package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Register;
import com.neuedu.his.po.Registlevel;
import com.neuedu.his.po.Settlecategory;
import com.neuedu.his.po.User;
import com.neuedu.his.service.RegisterService;
import com.neuedu.his.service.RegistlevelService;
import com.neuedu.his.service.SettlecategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    RegisterService service;

    @Autowired
    RegistlevelService levelService;

    @Autowired
    SettlecategoryService settlecategoryService;

    @RequestMapping("/listall")
     public List<Register> listAll(){
        return service.list();
    }
    @RequestMapping("/add")
    public Boolean add(@RequestBody Register r){
        r.setRegisttime(new Date());
        r.setVisitstate(1);
        r.setRegisterid(301);
        System.out.println(r);
        return service.save(r);
    }

    @RequestMapping("/change")
    public Boolean change(@RequestBody Map<String, String> params){
        String casenumber = params.get("casenumber");
        Register up = new Register();
        up.setVisitstate(2);
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("casenumber",casenumber);
        return service.update(up,qw);
    }

    @RequestMapping("/reglev")
    public List<Registlevel> reglev(){
        levelService.list().forEach(System.out::println);
        return levelService.list();
    }

    @RequestMapping("/settle")
    public List<Settlecategory> settle(){
        settlecategoryService.list().forEach(System.out::println);
        return settlecategoryService.list();
    }

    @RequestMapping("/list")
    public List<Register> list(@RequestParam Integer userid,@RequestParam Integer visitstate){
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("userid",userid).eq("visitstate",visitstate);
        return service.list(qw);
    }

    @RequestMapping("/list1")
    public List<Register> list1(@RequestParam Integer deptid,@RequestParam Integer visitstate){
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("deptid",deptid).eq("visitstate",visitstate);
        return service.list(qw);
    }

    @RequestMapping("/searchforidnumberaddress")
    public Register searchforidnumberaddress(@RequestBody Map<String, String> params){
        String casenumber=params.get("casenumber");
        QueryWrapper<Register> qw = new QueryWrapper<>();
        qw.eq("casenumber",casenumber);
        return service.list(qw).get(0);
    }
}
